package Presentation;

import Metier.Objets.Produit;
import java.awt.Color;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class ListePrincipaleVendeurCellRender extends JLabel implements ListCellRenderer {

    private final OngletVendeur onglet;

    public ListePrincipaleVendeurCellRender(OngletVendeur onglet) {
        super();
        this.onglet = onglet;
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        setBorder(new EmptyBorder(10, 10, 10, 10));
        setOpaque(true);
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(Color.white);
            setForeground(list.getForeground());
        }
        if (onglet.isPerime((Produit) value) || onglet.isInAlerte((Produit) value)) {
            Icon icon = new ImageIcon(getClass().getResource("/ressources/images/alerteIcon.png"));
            if (icon != null) {
                setIcon(icon);
            }
        } else {
            setIcon(null);
        }
        setText(value.toString());
        setHorizontalTextPosition(SwingConstants.LEFT);
        return this;
    }
}